﻿<div class="easyui-layout" data-options="fit: true">
    <!--表单-->
    <div class="panel-default p10" data-options="region:'north',border: false,split:true" style="height:300px;">
        <div class="form-inline">
            <form id="commonStockInFromValidate" name="commonStockInFromValidate" onsubmit="return false;">
                <style>
                    .t td {
                        padding: 3px;
                        line-height: 2;
                        vertical-align: middle;
                        border-bottom: 1px solid #ddd;
                        word-wrap: break-word;
                        word-break: break-all;
                    }
                </style>
                <table class="t" width="100%" border="0" cellspacing="0" cellpadding="0">
                    <tbody>
                        <tr>
                            <td class="t_r wd70">单据编号：</td>
                            <td class="t_l wd200">
                                <input name="nextId" class="form-control input-xs wd200" type="text" disabled="disabled" data-options="required:true,prompt:'单据编号'" value="@(ViewBag.NextId)">
                            </td>
                            <td class="t_l wd200"></td>
                            <td class="t_r wd70"><span class="red">*</span>容器编码：</td>
                            <td class="t_l wd200">
                                <select id="containerCode" name="containerCode" class="easyui-combobox wd200" data-options="valueField:'id',textField:'name',required:true,prompt:'容器编码'"></select>
                                <script type="text/javascript">
                                    $(function () {
                                        //获取控件
                                        var containerCode = $("#containerCode").comboselect({
                                            onDialog: function (target) {

                                                window.Topro.DAO.Container({
                                                    title: '容器',
                                                    isSingle: true,
                                                    selectingData: [],
                                                    saveCallBack: function (res) {
                                                        var list = $(containerCode).comboselect("getData");

                                                        list.push({
                                                            id: res.code,
                                                            name: res.code
                                                        });

                                                        $(containerCode).combobox('loadData', list);
                                                        $(containerCode).combobox("setValue", res.code);
                                                    }
                                                });

                                            }
                                        });
                                    });
                                </script>
                            </td>
                            <td class="t_r wd70"></td>
                            <td class=""></td>
                        </tr>
                        <tr>
                            <td class="t_r wd70"><span class="red">*</span>批号：</td>
                            <td class="t_l wd200">
                                <input maxlength="30" class="easyui-validatebox form-control input-xs wd200" type="text" id="lotNo" name="lotNo" autocomplete="off" data-options="required:true,prompt:'批号'">
                            </td>
                            <td class="t_l wd200"></td>
                            <td class="t_r wd70"><span class="red">*</span>空容器：</td>
                            <td class="t_l wd200">
                                <input type="checkbox" id="containerType" name="containerType" autocomplete="off">
                            </td>
                        </tr>
                        <tr>
                            <td class="t_r wd70">入库库位：</td>
                            <td class="t_l wd200">
                                <select id="warehouseUnitId" name="warehouseUnitId" class="easyui-combobox wd200" data-options="valueField:'id',textField:'name',prompt:'入库库位'"></select>
                                <script type="text/javascript">
                                    $(function () {
                                        //获取控件
                                        var warehouseUnitId = $("#warehouseUnitId").comboselect({
                                            onDialog: function (target) {
                                                Topro.DAO.WarehouseUnit({
                                                    title: '库位',
                                                    isSingle: true,
                                                    selectingData: [],
                                                    saveCallBack: function (res) {

                                                        var list = $(warehouseUnitId).comboselect("getData");

                                                        list.push({
                                                            id: res.id,
                                                            name: "{0}-{1}-{2}".format(res.pai, res.lie, res.ceng)
                                                        });

                                                        $(warehouseUnitId).combobox('loadData', list);

                                                        $(warehouseUnitId).combobox("setValue", res.id);
                                                    }
                                                });
                                            }
                                        });

                                    });
                                </script>
                            </td>
                            <td class="t_l wd200"></td>
                            <td class="t_r wd70">站台：</td>
                            <td class="t_l wd200">
                                <input maxlength="30" class="easyui-validatebox form-control input-xs wd200" type="text" id="stationNo" name="stationNo" autocomplete="off" data-options="prompt:'站台'">
                            </td>
                        </tr>
                        <tr>
                            <td class="t_r wd70">备注：</td>
                            <td class="t_l wd200">
                                <input maxlength="30" class="easyui-validatebox form-control input-xs wd200" type="text" id="remark" name="remark" autocomplete="off" data-options="prompt:'备注'">
                            </td>
                            <td class="t_l wd200">&nbsp;</td>
                            <td class="t_r wd70">&nbsp;</td>
                            <td class="t_l wd200">
                                <a class="btn btn-primary btn-xs" style="height:23px;" onclick="return page.selectProductStockIn();"><span class="iconfont icon-anonymous-iconfont f12 "></span>选择物料</a>
                            </td>
                        </tr>
                    </tbody>
                </table>
            </form>
        </div>
    </div>
    <!--
    <div class="tabtool">
        <span class="abs_r mt5 mr5"><a class="btn btn-primary btn-xs" style="height:23px;" onclick="return page.selectProductStockIn();"><span class="iconfont icon-anonymous-iconfont f12 "></span>选择物料</a></span>
    </div>
    -->
    <div data-options="region:'center',split: false, border: false">
        <div class="easyui-tabs" data-options="fit:true,plain:true,border:false">
            <table id="commonStockInDG"></table>
        </div>
    </div>
</div>
<div id="menu" class="easyui-menu">
    <div onclick="page.delete()" data-options="iconCls:'icon-add'">删除</div>
</div>
<script type="text/javascript">
    //定义
    var commonStockInDG = $('#commonStockInDG');

    $(function () {

        commonStockInDG.datagrid({
            fit: true,
            method: "get",
            url: "@Url.Action("ProductEmptyQuery", "Module")",
            queryParams: {},
            idField: 'id',
            remoteSort: false,
            multiSort: false,
            pagination: true,
            singleSelect: true,
            checkOnSelect: true,  //设置为 true，当用户点击某一行时，则会选中/取消选中复选框
            selectOnCheck: true,  //设置为 true，点击复选框将会选中该行
            rownumbers: true,
            autoEditing: true,
            columns: [
                [
                    {
                        field: 'name',
                        title: '物料名称',
                        width: 550,
                        align: 'left',
                    },
                    {
                        field: 'quantity',
                        title: '数量',
                        width: 75,
                        align: 'center',
                        editor: {
                            type: 'text',
                            options: {
                                required: true
                            }
                        }
                    },
                    {
                        field: 'code',
                        title: '条码 ',
                        width: 100
                    },
                    {
                        field: 'status',
                        title: '商品编码',
                        align: 'center',
                        width: 100
                    }
                ]
            ],
            rowTooltip: false,
            onRowContextMenu: function (e, rowIndex, rowData) {
                //阻止浏览器自带的右键菜单弹出
                e.preventDefault();
                //选中当前行
                $(this).datagrid('selectRow', rowIndex);
                //弹出窗口的方位坐标
                $('#menu').menu('show', {
                    left: e.pageX,
                    top: e.pageY
                });
            }
        });

        return;
        Topro.UI.DataGrid(commonStockInDG, {
            fit: true,
            method: "get",
            url: "@Url.Action("ProductEmptyQuery", "Module")",
            queryParams: {},
            idField: 'id',
            remoteSort: false,
            multiSort: false,
            pagination: true,
            singleSelect: true,
            checkOnSelect: true,  //设置为 true，当用户点击某一行时，则会选中/取消选中复选框
            selectOnCheck: true,  //设置为 true，点击复选框将会选中该行
            rownumbers: true,
            autoEditing: true,
            columns: [
                [
                    {
                        field: 'name',
                        title: '物料名称',
                        width: 550,
                        editor: {
                            type: 'comboselect',
                            options: {
                                textField: 'Pname',
                                valueField: 'Pvalue',
                                method: 'get',
                                url: '@Url.Action("ProductCategorys", "Common")',
                                required: false,
                                onDialog: function (target) {

                                    window.Topro.DAO.Product({
                                        title: '物料',
                                        isSingle: true,
                                        saveCallBack: function (updateRow) {
                                            var row = commonStockInDG.datagrid('getSelected');
                                            if (row) {
                                                var rowIndex = commonStockInDG.datagrid('getRowIndex', row);
                                                if (rowIndex < 0) {
                                                    window.top.$.messager.alert('提示', '请选择删除行.', 'info');
                                                }

                                                commonStockInDG.datagrid('updateRow', {
                                                    index: rowIndex,
                                                    row: updateRow
                                                })
                                            }
                                        }
                                    });

                                },
                                onSelect: function () {

                                }
                            }
                        }
                    },
                    {
                        field: 'quantity',
                        title: '数量',
                        width: 75,
                        align: 'center',
                        editor: {
                            type: 'text',
                            options: {
                                required: true
                            }
                        }
                    },
                    {
                        field: 'code',
                        title: '条码 ',
                        width: 100
                    },
                    {
                        field: 'status',
                        title: '商品编码',
                        align: 'center',
                        width: 100
                    }
                ]
            ],
            rowTooltip: false,
            onRowContextMenu: function (e, rowIndex, rowData) {
                //阻止浏览器自带的右键菜单弹出
                e.preventDefault();
                //选中当前行
                $(this).datagrid('selectRow', rowIndex);
                //弹出窗口的方位坐标
                $('#menu').menu('show', {
                    left: e.pageX,
                    top: e.pageY
                });
            }
        });
    });

    var page = {
        delete: function () {
            var row = commonStockInDG.datagrid('getSelected');
            if (row) {
                var rowIndex = commonStockInDG.datagrid('getRowIndex', row);
                if (rowIndex < 0) {
                    window.top.$.messager.alert('提示', '请选择删除行.', 'info');
                }

                commonStockInDG.datagrid('deleteRow', rowIndex);
            } else {
                window.top.$.messager.alert('提示', '请选择删除行.', 'info');
                return;
            }
        },
        queryParams: function () {
            var params = {
            };

            return params;
        },
        selectProductStockIn: function () {
            Topro.DAO.Product({
                title: '物料',
                isSingle: true,
                saveCallBack: function (rows) {
                    debugger
                    if (rows == null) {
                        Topro.UI.Tip_warning({ content: '请选择物料.', type: 'info' });
                        return;
                    } else {
                        /*
                        $.each(rows, function (i, row) {

                        });
                        */
                        //数量
                        rows.quantity = 1;

                        commonStockInDG.datagrid('insertRow', {
                            index: 1,
                            row: rows
                        })
                    }

                    return;
                }
            });
        },
        doSearch: function () {
            //绑定


        }
    }
</script>
